$(document).ready(function(){
	
	if($("#publishform")){
		$("#publishform").validate({
			rules: {
				title:{
					required : true,
					maxlength : 100
				},
				infoid: {
					required: true,
					digits:true
				},
				requirement: {
					required: true,
					maxlength:500
				},
				cname: {
					required: true
				},
				mobile: {
					required: true
				}
			},
			messages: {
				title:{
					required: "请输入标题",
					maxlength:"仅限100个字"
				},
				infoid: {
					required: "请输入信息编号",
					digits:"信息编号仅限数字"
				},
				requirement: {
					required: "请输入求购要求",
					maxlength:"仅限500个字"
				},
				cname: {
					required: "请输入联系人姓名"
				},
				mobile: {
					required: "请输入联系方式"
				}
			},
			submitHandler: function(form) {  
				$("#buttondiv").css("display" , "none");
				$("#fbmsg").css("display" , "");
				form.submit();  
			}
		});

		$("#submitbtn2").bind("click" , function(){
			$("#ispublic").val(1);
			$("#publishform").trigger("submit");
		});
	}
	
	if($("#infoid")){
		initTips($("#infoid"));
	}
	
	if($("#maintitle")){
		$("#maintitle").bind("click" , function(e){
			var el = e.target;
			var tag = el.tagName;
			if(tag=="INPUT"){
				$("#ispublic").val($(el).val());
				submitForm();
			}
		});
	}
	
	if($("#seachidbtn")){
		$("#seachidbtn").bind("click" , function(){
			submitForm();
		});
	}
	
	if($("#ordersel")){
		$("#ordersel").bind("change" , function(){
			$("#order").val($(this).val());
			submitForm();
		});
		
		$("#ordersel").val($("#order").val());
	}
	
	if($("#nextpage")){
		$("#nextpage").bind("click" , function(){
			var np = $min(parseInt($("#r_page").val())+1 , parseInt($("#totalpage").val()));
			$("#r_page").val(np);
			submitForm();
		});
		if($("#r_page").val()==$("#totalpage").val()){
			$("#nextpage").removeAttr("href");
		}else{
			$("#nextpage").attr("href" , "###");
		}
	}
	
	if($("#prepage")){
		$("#prepage").bind("click" , function(){
			var pp = $max(parseInt($("#r_page").val())-1 , 1);
			$("#r_page").val(pp);
			submitForm();
		});
		if($("#r_page").val()=="1"){
			$("#prepage").removeAttr("href");
		}else{
			$("#prepage").attr("href" , "###");
		}
	}
	
	if($("#checkAll1")){
		$("#checkAll1").bind("click" , selectAll);
		$("#checkAll2").bind("click" , selectAll);
	}
	
	if($("#upload1")){
		$("#upload1").bind("click" , uploadAll);
		$("#upload2").bind("click" , uploadAll);
	}
});

function submitForm(){
	if($("#listform")){
		if($("#infoid")&&$("#infoid").val()==$("#infoid").attr("tips")){$("#infoid").val("");}
		$("#listform").trigger("submit");
	}
}

function selectAll(){
	var status = this.checked;
	$("#uploadlist input[type='checkbox']").attr("checked", status); 
}

function uploadAll(){
	var ips = $("input[name='pchecker']");
	var arr = [];
	var upordown = $("#ispublic").val()=="0"?1:0;
	for(var i=0 , l = ips.length ; i<l ;i++){
		if(ips[i].checked==true){
			arr.push(ips[i].value);
		}
	}
	var ids = arr.join(",");
	$.get("qghouse_post.php", { action: "update", ids: ids , upordown : upordown },
	  function(data){
		if(data=="success"){
			location.href = $("#hidelink").val();
		}
	  }); 
}

	